﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthPostAction("ETL", "UpdateDataSourceParameters", "1.0")]
    public class UpdateDataSourceParametersAction : BaseAction<UpdateDataSourceParametersParams, UpdateDataSourceParametersResult>
    {
        protected override ActionResult<UpdateDataSourceParametersResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            UpdateDataSourceParametersParams opParams)
        {
            SER.DtSerService service = new SER.DtSerService();
            ServiceResult serResult = service.UpdateDataSourceParameters(context.UserId, opParams.ServiceId, opParams.SourceId, opParams.ParameterSettings);

            UpdateDataSourceParametersResult result = new UpdateDataSourceParametersResult();

            if (serResult.IsSuccess)
            {
                return new ActionResult<UpdateDataSourceParametersResult>(result);
            }
            else
            {
                return new ActionResult<UpdateDataSourceParametersResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class UpdateDataSourceParametersParams
    {
        [Parameter]
        public Guid ServiceId { get; set; }

        [Parameter]
        public Guid SourceId { get; set; }

        [Parameter]
        public string ParameterSettings { get; set; }
    }

    public class UpdateDataSourceParametersResult
    {
    }
}
